/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mousemover;

import java.awt.AWTException;
import java.awt.Robot;
import javax.swing.JOptionPane;

/**
 *
 * @author Cynic
 */
public class Mover extends Robot {

    private GUI gui;
    private int min;

    private Mover() throws AWTException {
        super();
        gui = new GUI();
        this.min = min;
    }

    static public Mover instantiate() {
        Mover mouse = null;
        try {
            mouse = new Mover();
        } catch (AWTException e) {
            System.err.println("Cannot create Robot Object!, Try Again");
        }
        return mouse;
    }

    public void run() {
        int min = 3;
        while (true) {
            try {
                min = gui.getMin();
                break;
            } catch (NumberFormatException e) {
                gui.setText("Enter a legal Number!");
            } catch (NullPointerException e) {
                int option = JOptionPane.showConfirmDialog(null, "Do you want to quit?");
                if (option == JOptionPane.OK_OPTION) {
                    return;
                }
            }
        }

        this.min = min;

        gui.setText("App Running");
        gui.setText("This Windows can be minimised!");


        while (true) {
            mouseWheel(1);
            mouseWheel(-1);
            try {
                Thread.sleep(min * 60 * 1000);
            } catch (InterruptedException e) {
                gui.setText("Cannot make the thread sleep!");
            }
        }
    }
}

